package com.yh.workbill.ui.addworkbill;

import com.yh.workbill.db.Company;
import com.yh.workbill.db.UnitCompany;
import com.yh.workbill.model.WorkDevices;

import java.util.List;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class AddWorkBillViewModel extends ViewModel {

    public AddWorkBillRepository repository;
    public MutableLiveData<WorkDevices> currentWorkDevices;

    public AddWorkBillViewModel() {
        repository = new AddWorkBillRepository();
    }

    public LiveData<List<Company>> getFindAllCompanys() {
        return repository.listCompany;
    }

    public LiveData<List<UnitCompany>> getFindAllUnitCompanys() {
        return repository.listUnitCompany;
    }

    public void addCompany(String company_name) {
        repository.addCompany(company_name);
    }

    public void addUnitCompany(String unit_name) {
        repository.addUnitCompany(unit_name);
    }


    public MutableLiveData<WorkDevices> getCurrentWorkDevices() {
        if (currentWorkDevices == null) {
            currentWorkDevices = new MutableLiveData<>();
            currentWorkDevices.setValue(new WorkDevices());
        }
        return currentWorkDevices;
    }

    public void setCurrentWorkDevices(WorkDevices data) {
        WorkDevices value = currentWorkDevices.getValue();
        if (value == null) {
            value = new WorkDevices();
        }
        currentWorkDevices.postValue(data);
    }
}
